<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                template="../templates/principal.xhtml">

    <ui:define name="content" id="content">        
        <h:form id="frmPropostaModelo">
            <p:growl id="messages" life="5000" showDetail="true" showSummary="true" />

            <p:panel id="panel" header="Bem Vindo ao Cadastro de Modelo de Proposta">

                <p:dataTable id="tabPropostaModelo" widgetVar="wtabPropostaModelo" var="propostaModelo" value="#{propostaModeloBean.lazyModel}" 
                             paginator="true" rows="15" paginatorPosition="top" emptyMessage="Nenhum Registro Retornado ..." lazy="true" filterEvent="enter">

                    <p:column headerText="Descrição" sortBy="#{propostaModelo.dscModelo}" filterBy="#{propostaModelo.dscModelo}" style="text-align: left">
                        <h:outputText value="#{propostaModelo.dscModelo}" />
                    </p:column>

                    <p:column style="width: 100px;">
                        <h:panelGrid columns="4" styleClass="actions" cellpadding="0">
                            <p:commandButton id="selectButton" update=":frmPropostaModelo:panel, :frmPropostaModelo:messages" 
                                             process="@all" icon="ui-icon-search" title="Visualizar // Alterar Modelo de Proposta" 
                                             oncomplete="PF('propostaModeloDialogEditor').show(); PF('propostaModeloDialogEditor').toggleMaximize();">
                                <f:setPropertyActionListener value="#{propostaModelo}" target="#{propostaModeloBean.selectedPropostaModelo}" />
                                <f:setPropertyActionListener value="#{false}" target="#{propostaModeloBean.altera}" />
                            </p:commandButton>

                            <p:commandButton id="excluirButton" update=":frmPropostaModelo:panel, :frmPropostaModelo:messages" 
                                             icon="ui-icon-trash" title="Excluir Modelo de Proposta" oncomplete="PF('confirmation').show();">
                                <f:setPropertyActionListener value="#{propostaModelo}" target="#{propostaModeloBean.selectedPropostaModelo}" />
                            </p:commandButton>
                        </h:panelGrid>
                    </p:column>

                    <f:facet name="footer">
                        <div style="text-align: left;">
                            <p:commandButton id="incluirButton" actionListener="#{propostaModeloBean.preparaInserir}" process="@this"
                                             update=":frmPropostaModelo:panel, :frmPropostaModelo:dialogPropostaModeloEditor, :frmPropostaModelo:messages"  value="Novo Modelo de Proposta"
                                             icon="ui-icon-pencil" title="Cadastrar Novo Modelo de Proposta" oncomplete="PF('propostaModeloDialogEditor').show(); PF('propostaModeloDialogEditor').toggleMaximize();" />
                        </div>
                    </f:facet>
                </p:dataTable>

                <!-- DETALHES MODELO DE PROPOSTA -->
                <p:dialog id="dialogPropostaModeloEditor" header="Detalhes Modelo de Proposta" widgetVar="propostaModeloDialogEditor" resizable="true" maximizable="true"
                          showEffect="explode" hideEffect="explode" style="text-align: left;" position="center,top" onHide="PF('propostaModeloDialogEditor').toggleMaximize();">
                    <p:panel id="panelPropostaModelo">

                        <p:panelGrid id="displayPropostaModelo" style="width: 100%;">
                            <p:row>
                                <p:column>
                                    <h:outputText value="Descrição:" />
                                    <p:inputText id="inDescricao" value="#{propostaModeloBean.selectedPropostaModelo.dscModelo}" maxlength="200" style="width:1500px; font-weight:bold; " />
                                </p:column>
                            </p:row>

                            <p:row>
                                <p:column>
                                    <p:fieldset id="fieldLogo" legend="Macros">
                                        <p:selectOneRadio id="customRadio" value="#{propostaModeloBean.itemlogo}" layout="custom" onchange="javascript:insertCurCaret(this.value)">
                                            <f:selectItem itemLabel="Option 1" itemValue="#NOME_CLIENTE#" />
                                            <f:selectItem itemLabel="Option 2" itemValue="#ENDERECO_CLIENTE#" />
                                            <f:selectItem itemLabel="Option 3" itemValue="#NOME_EMPREENDIMENTO#" />
                                            <f:selectItem itemLabel="Option 4" itemValue="#ASSUNTO_EMPREENDIMENTO#" />
                                            <f:selectItem itemLabel="Option 5" itemValue="#ENDERECO_EMPREENDIMENTO#" />
                                            <f:selectItem itemLabel="Option 6" itemValue="#DATA_EXTENSO_COM_CIDADE#" />
                                            <f:selectItem itemLabel="Option 7" itemValue="#DATA_EXTENSO_SEM_CIDADE#" />
                                            <f:selectItem itemLabel="Option 8" itemValue="#ENDERECOS_EMPREENDIMENTO#" />
                                            <f:selectItem itemLabel="Option 9" itemValue="#TOTAL_PROPOSTA#" />
                                            <f:selectItem itemLabel="Option 10" itemValue="#ASSINATURA_EMPRESA#" />
                                            <f:selectItem itemLabel="Option 11" itemValue="#ASSINATURA_CLIENTE#" />
                                            <f:selectItem itemLabel="Option 12" itemValue="#B" />
                                            <f:selectItem itemLabel="Option 13" itemValue="#/B" />
                                            <f:selectItem itemLabel="Option 14" itemValue="" />
                                        </p:selectOneRadio>
                                        <p:panelGrid>
                                            <p:row>
                                                <p:column>
                                                    <p:radioButton id="opt1" for="customRadio" itemIndex="0" />
                                                </p:column>
                                                <p:column>
                                                    <h:outputText value="Nome do Cliente:" />
                                                </p:column>

                                                <p:column>
                                                    <p:radioButton id="opt2" for="customRadio" itemIndex="1" />
                                                </p:column>
                                                <p:column>
                                                    <h:outputText value="Endereço do Cliente:" />
                                                </p:column>

                                                <p:column>
                                                    <p:radioButton id="opt3" for="customRadio" itemIndex="2" />
                                                </p:column>
                                                <p:column>
                                                    <h:outputText value="Nome do Empreendimento:" />
                                                </p:column>

                                                <p:column>
                                                    <p:radioButton id="opt4" for="customRadio" itemIndex="3" />
                                                </p:column>
                                                <p:column>
                                                    <h:outputText value="Assunto Empreendimento:" />
                                                </p:column>

                                                <p:column>
                                                    <p:radioButton id="opt5" for="customRadio" itemIndex="4" />
                                                </p:column>
                                                <p:column>
                                                    <h:outputText value="Endereço do Empreendimento:" />
                                                </p:column>

                                                <p:column>
                                                    <p:radioButton id="opt6" for="customRadio" itemIndex="5" />
                                                </p:column>
                                                <p:column>
                                                    <h:outputText value="Data por Extenso com Cidade:" />
                                                </p:column>

                                                <p:column>
                                                    <p:radioButton id="opt7" for="customRadio" itemIndex="6" />
                                                </p:column>
                                                <p:column>
                                                    <h:outputText value="Data por Extenso sem Cidade:" />
                                                </p:column>
                                            </p:row>
                                            <p:row>
                                                <p:column>
                                                    <p:radioButton id="opt8" for="customRadio" itemIndex="7" />
                                                </p:column>
                                                <p:column>
                                                    <h:outputText value="Todos os Endereços do Empreendimento:" />
                                                </p:column>

                                                <p:column>
                                                    <p:radioButton id="opt9" for="customRadio" itemIndex="8" />
                                                </p:column>
                                                <p:column>
                                                    <h:outputText value="Total da Proposta:" />
                                                </p:column>

                                                <p:column>
                                                    <p:radioButton id="opt10" for="customRadio" itemIndex="9" />
                                                </p:column>
                                                <p:column>
                                                    <h:outputText value="Assinatura Empresa:" />
                                                </p:column>

                                                <p:column>
                                                    <p:radioButton id="opt11" for="customRadio" itemIndex="10" />
                                                </p:column>
                                                <p:column>
                                                    <h:outputText value="Assinatura Cliente:" />
                                                </p:column>
                                                
                                                <p:column>
                                                    <p:radioButton id="opt12" for="customRadio" itemIndex="11" />
                                                </p:column>
                                                <p:column>
                                                    <h:outputText value="Abrir Negrito" />
                                                </p:column>
                                                
                                                <p:column>
                                                    <p:radioButton id="opt13" for="customRadio" itemIndex="12" />
                                                </p:column>
                                                <p:column>
                                                    <h:outputText value="Fechar Negrito" />
                                                </p:column>
                                                
                                                <p:column>
                                                    <p:radioButton id="opt14" for="customRadio" itemIndex="13" />
                                                </p:column>
                                                <p:column>
                                                    <h:outputText value="Limpar" />
                                                </p:column>
                                            </p:row>
                                        </p:panelGrid>
                                    </p:fieldset>
                                </p:column>
                            </p:row>
                            <p:row>
                                <p:column>
                                    <p:fieldset legend="Etapa - Honorários">
                                        <p:panelGrid>
                                            <p:row>
                                                <p:column>
                                                    <p:inputText id="inDescricaoEtapa" value="#{propostaModeloBean.selectedPropostaModelo.idEtapa.nomEtapa}" readonly="true" style="width:500px; font-weight:bold; " />
                                                    <p:commandButton id="selectButtonEtapa" value="Pesquisar Etapas - Honorários" update=":frmPropostaModelo:tabPropostaEtapa :frmPropostaModelo:messages" 
                                                                     icon="ui-icon-search" title="Pesquisar Etapas - Honorários" oncomplete="PF('propostaEtapaDialog').show()" />
                                                </p:column>

                                            </p:row>

                                        </p:panelGrid>
                                    </p:fieldset>
                                </p:column>
                            </p:row>
                            <p:row>
                                <p:column>
                                    <p:inputTextarea autoResize="false" style="width: 100%;" rows="30"  id="editorModelo" widgetVar="weditorModelo" value="#{propostaModeloBean.selectedPropostaModelo.modelo}" />
                                </p:column>
                            </p:row>

                            <f:facet name="footer">
                                <p:row>
                                    <p:column>
                                        <p:commandButton value="Inserir" icon="ui-icon-disk" update=":frmPropostaModelo:panel :frmPropostaModelo:messages" rendered="#{propostaModeloBean.altera}"
                                                         process="@form" actionListener="#{propostaModeloBean.inserir}" oncomplete="PF('propostaModeloDialogEditor').hide();" />
                                        <p:commandButton value="Alterar" icon="ui-icon-disk" update=":frmPropostaModelo:panel :frmPropostaModelo:messages" rendered="#{!propostaModeloBean.altera}"
                                                         process="@form" actionListener="#{propostaModeloBean.alterar}" oncomplete="PF('propostaModeloDialogEditor').hide();" />
                                        <p:commandButton icon="ui-icon-closethick" value="Fechar" onclick="PF('propostaModeloDialogEditor').hide();" title="Fecha Janela dos Modelo de Propostas!" />
                                    </p:column>
                                </p:row>
                            </f:facet>
                        </p:panelGrid> 
                    </p:panel>
                </p:dialog> 

                <p:dialog header="Confirma a Exclusão desse Modelo de Proposta: #{propostaModeloBean.selectedPropostaModelo.dscModelo}? " widgetVar="confirmation">  

                    <p:commandButton value="Sim" update=":frmPropostaModelo:panel, :frmPropostaModelo:messages" oncomplete="PF('confirmation').hide(); PF('propostaModeloDialogEditor').hide();"
                                     process="@this" actionListener="#{propostaModeloBean.excluir}" />  
                    <p:commandButton value="Não" onclick="PF('confirmation').hide();" type="button" />   

                </p:dialog>

                <!-- PESQUISA ETAPA -->
                <p:dialog id="dialogPropostaEtapa" header="Detalhes Etapas - Honorários" widgetVar="propostaEtapaDialog" resizable="true" dynamic="true"
                          width="1200" showEffect="explode" hideEffect="explode" style="text-align: left;" position="right,top">

                    <p:dataTable id="tabPropostaEtapa" widgetVar="wtabPropostaEtapa" var="propostaEtapa" value="#{propostaEtapaBean.lazyModel}" paginator="true" rows="15" 
                                 paginatorPosition="top" emptyMessage="Nenhum Registro Retornado ..." lazy="true" filterEvent="enter">

                        <p:ajax event="rowToggle" listener="#{propostaEtapaBean.onRowToggle}" update=":frmPropostaModelo:tabPropostaEtapa" />

                        <p:column style="width:4%">   
                            <p:rowToggler />
                        </p:column>

                        <p:column headerText="Nome da Etapa" sortBy="#{propostaEtapa.nomEtapa}" filterBy="#{propostaEtapa.nomEtapa}" style="text-align: left">
                            <h:outputText value="#{propostaEtapa.nomEtapa}" />
                        </p:column>

                        <p:rowExpansion>
                            <p:dataTable id="tabPropostaEtapaDesc" var="propostaEtapaDesc" value="#{propostaEtapa.propostaEtapaDescList}" paginator="true" rows="15" 
                                         paginatorPosition="top" emptyMessage="Nenhum Registro Retornado ..." filterEvent="enter">

                                <p:column headerText="No.Etapa" sortBy="#{propostaEtapaDesc.numEtapa}" filterBy="#{propostaEtapaDesc.numEtapa}" style="text-align: left">
                                    <h:outputText value="#{propostaEtapaDesc.numEtapa}" />
                                </p:column>

                                <p:column headerText="Primeira Descrição" sortBy="#{propostaEtapaDesc.dscEtapa1}" filterBy="#{propostaEtapaDesc.dscEtapa1}" style="text-align: left">
                                    <h:outputText value="#{propostaEtapaDesc.dscEtapa1}" />
                                </p:column>

                                <p:column headerText="Segunda Descrição" sortBy="#{propostaEtapaDesc.dscEtapa2}" filterBy="#{propostaEtapaDesc.dscEtapa2}" style="text-align: left">
                                    <h:outputText value="#{propostaEtapaDesc.dscEtapa2}" />
                                </p:column>
                            </p:dataTable>
                        </p:rowExpansion>

                        <p:column style="width: 50px;">
                            <h:panelGrid columns="4" styleClass="actions" cellpadding="0">
                                <p:commandButton id="selectButton" update=":frmPropostaModelo:panelPropostaModelo, :frmPropostaModelo:messages" 
                                                 icon="ui-icon-search" title="Pesquisar Etapas - Honorários" oncomplete="PF('propostaEtapaDialog').hide();">
                                    <f:setPropertyActionListener value="#{propostaEtapa}" target="#{propostaModeloBean.selectedPropostaEtapa}" />
                                </p:commandButton>

                            </h:panelGrid>
                        </p:column>

                    </p:dataTable>
                </p:dialog>


            </p:panel>
        </h:form>
    </ui:define>
</ui:composition>

